<template>
	<view class="page">
		<u-sticky bgColor="#fff">
					 <u-tabs :list="utabs"  @change="tabChange" :current="active" :scrollable="false"></u-tabs>
		</u-sticky>
		<view class="" style="margin-top: 30rpx;" v-for="i in list[active]">
			<view class="block">
				<view class="head flex-SB">
					<view class="title">
						{{i.name}}
					</view>
				</view>
				<view class="content">
					<view style="height: 14px;line-height: 14px;font-size: 14px;color: #999;font-weight: 500;">时间：{{$u.timeFormat(i.end_time, 'yyyy年mm月dd日 hh:MM')}}</view>
				</view>
				<view class="head flex-SB">
					<view class="title">
						<view>类型：{{i.type=='train'?'训练':'测评'}}</view>
					</view>
					<view @tap="checkType(i)" class="startbtn">
						查看结果
					</view>
				</view>
			</view>
		</view>
		<view class="_h100"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone:'',
				trainData: [
				],
				list: [[],[]
				],
				active: 0,
				testInit:false,
				trainInit:false,
				utabs:[
					{name:'测评'},
					{name:'训练'},
				]
			};
		},
		onLoad() {
			this.phone = uni.getStorageSync('phone')||''
			uni.$u.http.post('/client/test_record', {
				phone:this.phone
			}).then(res => {
				this.testInit = true;
				// this.trainData = [...this.trainData,...res.data.testData];
				this.list[0] = res.data.testData;
			})

		},
		methods:{
			tabChange(n, t) {
				this.active = n.index;
				if (n.index == 1) {
					if(!this.trainInit){
						uni.$u.http.post('/client/train_record', {
							phone:this.phone
						}).then(res => {
							this.trainInit = true;
							this.list[n.index] = res.data.trainData
						})
					}
				}
			},
			checkType(obj){
				if(obj.type=='train'){
				    uni.navigateTo({
				    	url:'/pagesA/pages/testMain/testReport?id='+obj.id,
				    })
				}
				if(obj.type=='test'){
					if([92,120,122].includes(parseInt(obj.id))){
				    // if(obj.name=='大五人格' || obj.name=='大五人格量表 FFI'){
						uni.navigateTo({
							url:'/pagesA/pages/testMain/testReportA?id='+obj.id
						})
				    }else{
				        uni.navigateTo({
				        	url:'/pagesA/pages/testMain/testReportB?id='+obj.id
				        })
				    }
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.head {
		padding: 12rpx;
	}

	.title {
		height: 80rpx;
		line-height: 80rpx;
		color: #333;
		font-size: 32rpx;
		font-weight: 500;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.startbtn {
		width: 200rpx;
		height: 76rpx;
		line-height: 76rpx;
		text-align: center;
		border-radius: 38rpx;
		background: #E7FFFE;
		color: #1d6efa;
		opacity: 1;
		border: 2rpx solid;
	}

	.content {
		padding: 12rpx;
		line-height: 40rpx;
		font-size: 28rpx;
		color: #333;
	}
</style>